package com.chezhujie.www.service;

import com.chezhujie.www.domain.Czjcommodityimage;
import com.chezhujie.www.persistence.CzjcommodityimageMapper;
import com.xy.core.exception.ClassCheckException;
import com.xy.user.base.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 商品图片表
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class CzjcommodityimageService extends BaseService<Czjcommodityimage> {
    @Autowired
    private CzjcommodityimageMapper czjcommodityimageMapper;

    @Autowired
    public void setBaseMapper(CzjcommodityimageMapper czjcommodityimageMapper) {
        this.baseMapper = czjcommodityimageMapper;
    }

    public List<Map<String,Object>> getListCommodityId(Map<String, Object> param) {
        return czjcommodityimageMapper.listCommodityId(param);
    }

    public void checkEntity(Czjcommodityimage czjcommodityimage) throws ClassCheckException {
        if(czjcommodityimage.getImagePath()!=null&&czjcommodityimage.getImagePath().length()>255){
            throw new ClassCheckException("商品图片表图片地址不能超过255个字符");
        }
    }
    public void checkListEntity(List<Czjcommodityimage> listCzjcommodityimage) throws ClassCheckException {

        for (Czjcommodityimage czjcommodityimage : listCzjcommodityimage) {
            checkEntity(czjcommodityimage);
        }

    }

    @Override
    public void insert(Czjcommodityimage czjcommodityimage) {
        czjcommodityimage.setApproveStatus(0);
        czjcommodityimage.setCreateTime(new Date());
        czjcommodityimage.setDelFlag(0);
        super.insert(czjcommodityimage);
    }
    /**
     * 修改审批状态
     * @param id
     * @param approveStatus
     */
    public void changeApprove(String id, Integer approveStatus) {
        Czjcommodityimage entity = queryById(id);
        entity.setApproveStatus(approveStatus);
        entity.setApproveTime(new Date());
        update(entity);
    }
    @Override
    public void saves(List<Czjcommodityimage> list) {
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setApproveStatus(0);
            list.get(i).setCreateTime(new Date());
            list.get(i).setDelFlag(0);
        }
        super.saves(list);
    }

	public void deleteByIdAndType(Map<String, Object> map) {
		czjcommodityimageMapper.deleteByIdAndType(map);
	}

}
